<template>
  <div>
    <!-- <div class="content"> -->

    <!-- <div class="navigationHead">
      <div class="rootSetBtn">
      <el-button type="info">权限设置</el-button>
      </div>
    </div> -->

    <el-card class="box-card">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="管理员名字" prop="rootName">
          <el-input v-model.number="ruleForm.rootName"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.pass"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-form-item label="确认密码" prop="checkPass">
          <el-input
            type="password"
            v-model="ruleForm.checkPass"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="success" class="formBtn" @click="submitForm('ruleForm')"
            >确认添加</el-button
          >

          <!-- <el-button type="info" class="formBtn">权限设置</el-button> -->
          
          <el-button type="info" @click="resetForm('ruleForm')" class="formBtn">重置</el-button>


        </el-form-item>
      </el-form>
    </el-card>
    <!-- </div> -->
  </div>
</template>

<script>
export default {
  data() {
    var checkrootName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("管理员名字不能为空"));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error("请输入数字值"));
        } else {
          if (value < 18) {
            callback(new Error("必须年满18岁"));
          } else {
            callback();
          }
        }
      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: "",
        checkPass: "",
        rootName: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
        rootName: [{ validator: checkrootName, trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    cancel() {
      this.$router.push("/Adminlogin");
    },
  },
};
</script>

<style scoped>

/* body{
  background-image: url();
} */

.content {
  /* text-align: center;
  width: 40rem;
  height: 23rem;

  margin-left: 25%;
  margin-top: 12%; */

  background-color: blueviolet;
}

.box-card {
  /* padding: 2rem; */
  width: 40%;
  height: 23%;
  margin-left: 27%;
  margin-top: 10.6%;
  text-align: center;
  padding-right: 3%;
  padding-top: 2%;
  float: left;
}

.formBtn{
  width: 22%;
}
/* .navigationHead{
  float:right;
  width: 100%;
  margin-top: 3%;
} */

/* .rootSetBtn {
  float: right;
  margin-right: 10%;
} */
</style>